home *** CD-ROM | disk | FTP | other *** search
Wrap
from JascApp import * import JascUtils def ScriptProperties(): return { 'Author': 'Joe Fromm', 'Copyright': 'Copyright (C) 2002-2003, Jasc Software Inc., All Rights Reserved. Permission to create derivate works of this script is granted provided this copyright notice is included', 'Description': 'The the current image and split to RGB, putting the separate channels back as layers in a layer group.', 'Host': 'Paint Shop Pro', 'Host Version': '8.00' } def Do(Environment): if JascUtils.RequireADoc( Environment ) == App.Constants.Boolean.false: return # keep track of the doc we are starting with TargetDoc = App.TargetDocument # start by splitting the current image. App.Do( Environment, 'SplitToRGB', { 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Default, 'AutoActionMode': App.Constants.AutoActionMode.Match } }) # the split created 3 new documents and puts them at the end of the open list. # make a three element list that we can reorder. At this point we don't # care about the contents, just that it has three elements NewDocs = App.Documents[-3:] # grab the last three docs # now loop over the three newest docs. for ChannelDoc in App.Documents[-3:]: Name = ChannelDoc.Title if Name.find( 'Blue' ) != -1: NewDocs[0] = ChannelDoc # make Blue first elif Name.find( 'Green' ) != -1: NewDocs[1] = ChannelDoc # make Green next elif Name.find( 'Red' ) != -1: NewDocs[2] = ChannelDoc # make Red last FirstChannel = App.Constants.Boolean.true # need special handling on the first one # We use explicit specification of which document to work on by adding a fourth # parameter to the App.Do call. For operations on one of the single channel # images we use one of the saved docs. For operations on the original doc we use # the saved TargetDoc. for Doc in NewDocs: # this shouldn't be necessary, but at the moment paste as new layer has a bug, # so we promote manually. This assumes the original image is RGB. App.Do( Environment, 'IncreaseColorsTo16Million', {}, Doc ) # copy it to the clipboard App.Do( Environment, 'Copy', {}, Doc ) # paste it into the existing document - note the specification of target doc App.Do( Environment, 'PasteAsNewLayer', {}, TargetDoc ) # when we pasted it the layer came in as Raster Layer n, and we want to know what # channel it represents, so pick up the image title and use that to determine # the layer name. Out of split to RGB the image will be named RedN, GreenN, and BlueN. NewLayerName = Doc.Title if NewLayerName.find( 'Blue' ) != -1: NewLayerName = 'Blue Channel' elif NewLayerName.find( 'Green' ) != -1: NewLayerName = 'Green Channel' else: NewLayerName = 'Red Channel' # now that we have the layer name, rename it App.Do( Environment, 'LayerProperties', { 'General': { 'Name': NewLayerName, }, 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Silent, 'AutoActionMode': App.Constants.AutoActionMode.Default } }, TargetDoc ) # we want the channels to end up inside of a layer group, so after we # paste the first channel in create a layer group to hold it, and then select # the layer inside the group so subsequent creates go where we want them. if FirstChannel == App.Constants.Boolean.true: FirstChannel = App.Constants.Boolean.false # create the layer group App.Do( Environment, 'NewLayerGroup', { 'General': { 'Name': 'RGB Channels', }, 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Silent, 'AutoActionMode': App.Constants.AutoActionMode.Match } }, TargetDoc ) # select the member of the group rather than the group itself NewLayer = App.Do( Environment, 'SelectLayer', { 'Path': (0,0,[1],App.Constants.Boolean.false), 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Silent, 'AutoActionMode': App.Constants.AutoActionMode.Default } }, TargetDoc) # do the close in silent mode since we don't want to save changes App.Do( Environment, 'FileClose', { 'GeneralSettings': { 'ExecutionMode': App.Constants.ExecutionMode.Silent, 'AutoActionMode': App.Constants.AutoActionMode.Match } }, Doc )